﻿@using CoralNode.Core.Entity.Domains.Prototype
@using CoralNode.Core.Entity.Domains.Site
@using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Helper
@using Coralcode.Utils.Basic
@model CoralNode.Core.Entity.Domains.Node.NodeDomain
@{
    MenuDomain menu = ViewBag.Menu;
    Layout = null;
    bool isSeo = false;
}
<script src="/Themes/CoralAdmin/_misc/scripts/ueditor/ueditor.all.js"> </script>
<script src="/Themes/CoralAdmin/_misc/scripts/ueditor/ueditor.config.js"> </script>
<div>
    <div class=" scrolltab-triggers extra_normal">
        <a href="javascript:">主要信息</a>
        @foreach (PrototypeFieldGroupDomain group in @ViewBag.FieldGroupList) {
            if (group.FieldList.Count(n => n.FieldType == NodeEnums.FunctionFieldType.Seo) > 0) {
                isSeo = true;
            }
            <a href="javascript:">@group.Title</a>
        }
        @if (isSeo) {
            <a href="javascript:">SEO设置</a>
        }
    </div>
    <form id="spform" action="/m/node/createNode?categoryId=@Model.CategoryId&prototypeId=@Model.PrototypeId" method="post">
        @if (@ViewBag.Msg != null) {
            <div class="error_msg">
                @ViewBag.Msg.Msg
            </div>
        }
        <div class="pt_2 scrolltab-items">
            <div class="table_form form_main">
                <div class="scrolltab-item-t">
                    <span class="btn"></span>主要信息
                </div>
                <div class="pl_2">
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)
                    <table>
                        <tbody>
                            <tr>
                                <th width="60"><span class="signmark">*</span>标题：</th>
                                <td>
                                    @Html.TextBoxFor(m => m.Title, new { @class = "text w_37 required" })
                                    @Html.HiddenFor(n => n.SiteId)
                                    <input type="hidden" name="PrototypeId" value="@Model.PrototypeId"/>
                                </td>
                            </tr>
                            <tr>
                                <th>所属分类：</th>
                                <td>
                                    <div class="ztreeContainer">
                                        <input type="text" class="text js_ztree_trigger w_30" value="" id="category_title" />
                                        <input type="hidden" name="CategoryId" id="category_id" value="" />
                                        <span><a id="menuBtn" href="#" class="js_ztree_trigger">选择</a></span>
                                        <ul id="categoryTree" class="ztree" style="margin-top: 0; width: 180px;"></ul>
                                        <textarea class="js_ztree_data">@ViewBag.CategoryList</textarea>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th>排序：</th>
                                <td>@Html.TextBoxFor(m => m.Rank, new { @class = "text w_37" })
                                </td>
                            </tr>
                            <tr>
                                <th>发布时间：</th>
                                <td>
                                    <input type="text" class="text w_13 datepicker" name="CreateTime" value="@Model.CreateTime.ToString("yyyy-MM-dd HH:mm")"/>
                                </td>
                            </tr>
                            <tr>
                                <th>内容状态：</th>
                                <td>
                                    @foreach (var item in @ViewBag.NodeStatusList) {
                                        if (Model.Status == @item.Value) {
                                        <label class="mr_2">
                                            <input name="Status"  class="radio" checked="checked" type="radio" value="@item.Value"><span>@item.Key</span></label>
                                        } else {
                                        <label class="mr_2">
                                            <input name="Status" class="radio" type="radio" value="@item.Value"><span>@item.Key</span></label>
                                        }
                                    }
                                </td>
                            </tr>

                            @if (@ViewBag.ProcessList.Length > 0) {
                                foreach (var pro in ViewBag.ProcessList) {
                                <tr>
                                    <th style="width: 80px;">
                                        <label>@pro.Title：</label>
                                    </th>
                                    <td>
                                        <div class="slt js-select" name="process.@(pro.Code)" wd="264" swd="220">
                                            <div class="curr"><span></span></div>
                                            <div class="show">
                                                <ul>
                                                    @foreach (var item in @pro.EntryList) {
                                                        if (pro.DefaultValue == @item.EntryValue) {
                                                        <li  selected="selected" val="@item.EntryValue"><a>@item.EntryName</a></li>
                                                        } else {
                                                        <li  val="@item.EntryValue"><a>@item.EntryName</a></li>
                                                        }
                                                    }
                                                </ul>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
            </div>
            @foreach (PrototypeFieldGroupDomain group in @ViewBag.FieldGroupList) {
@*<div class="switch_tab">
                            <span class="btn"><i class="ico ico_slideswitch_show"></i></span>@group.Title
                        </div>*@
                <div class="table_form form_main">
                    <div class="scrolltab-item-t">
                        <span class="btn"></span>@group.Title
                    </div>
                    <div class="pl_2">
                        <table>
                            <tbody>

                                @foreach (var item in group.FieldList.Where(n => n.FieldType != NodeEnums.FunctionFieldType.Seo)) {
                                    <tr>
                                        <th width="80px">@item.Title：</th>
                                        <td>
                                            @if (@item.FieldType == NodeEnums.BasicFieldType.TextField) {
                                                if (string.IsNullOrEmpty(@item.Measurement)) {
                                                <input class="text w_37" type="text" name="field.@item.FieldName" validate="@item.Validator" value="@item.DefaultValue" />
                                                } else {
                                                <input class="text @item.Measurement w_15" type="text" name="field.@item.FieldName" validate="@item.Validator" value="@item.DefaultValue" />
@*<span class="l ml_2">@item.Measurement</span>*@
                                                }
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.TextArea) {
                                                <textarea name="field.@item.FieldName" validate="@item.Validator" class="h_8 w_37">@item.DefaultValue</textarea>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.PasswordField) {
                                                <input name="field.@item.FieldName" class="text w_37" type="password" validate="@item.Validator" value="@item.DefaultValue"/>
                                                <div class="exp ml_1">@item.Hint</div>
                                       
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.RadioButton) {
                                                foreach (var e in @item.EntryList) {
                                                    if (@e.EntryValue == @item.DefaultValue) {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" validate="@item.Validator" class="radio" checked="checked" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                    } else {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" validate="@item.Validator" class="radio" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                    }
                                                }
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.CheckBox) {
                                                foreach (var e in @item.EntryList) {
                                                    if (@ManageHtmlHelper.Contains(@item.DefaultValue, @e.EntryValue)) {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" validate="@item.Validator" class="checkbox"  checked="checked" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                    } else {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" validate="@item.Validator" class="checkbox" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                    }
                                                <div class="exp ml_1">@item.Hint</div>
                                                }

                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.SelectBox) {
                                                <select validate="@item.Validator" name="field.@item.FieldName" style="width:382px">
                                                    @foreach (var e in @item.EntryList) {
                                                        if (@e.EntryValue == @item.DefaultValue) {
                                                        <option value="@e.EntryValue" selected="selected">@e.EntryName</option>
                                                        } else {
                                                        <option value="@e.EntryValue">@e.EntryName</option>
                                                        }
                                                    }

                                                </select>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.FileField) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:false,method:'add',type:'file'}">
                                                        <span class="ico ico_upload_file"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiFile) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:true,method:'add',type:'file'}">
                                                        <span class="ico ico_upload_file"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.ImageField) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:false,method:'add',type:'image'}">
                                                        <span class="ico ico_upload_image"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiImage) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:true,method:'add',type:'image'}">
                                                        <span class="ico ico_upload_image"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (item.FieldType == NodeEnums.BasicFieldType.SingleData) {
                                                <a class="j_addRelation" num="@item.Measurement" val="@item.DefaultValue" href="/m/node/singlerelation?PrototypeId=@item.DefaultValue">
                                                    请选择@(item.Dataset)</a>
                                                if (item.Measurement == "1") {
                                                <input type="hidden" name="field.@item.FieldName" />
                                                } else {
                                                <input type="hidden" name="field.@item.FieldName" />
                                                }

                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.BlockOnTop) {
                                                foreach (var block in ViewBag.StaticBlockList) {
                                                <label class="mr_2">
                                                    <input class="checkbox" name="block.TopOn" type="checkbox"  value="@block.Id">
                                                    <span>@block.Title</span>
                                                </label>
                                                }
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.StatVisitInitial) {
                                                <ul>
                                                    <li>
                                                        <label>初始PV数</label><input class="text w_37" type="text" name="VisitStat.PageView" value="@item.DefaultValue" />
                                                    </li>
                                                    <li>
                                                        <label>初始UV数</label><input class="text w_37" type="text" name="VisitStat.UniqueVisitor" value="@item.DefaultValue" />
                                                    </li>
                                                    <li>
                                                        <label>初始IP数</label><input class="text w_37" type="text" name="VisitStat.IpCount" value="@item.DefaultValue" />
                                                    </li>
                                                </ul>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Tag) {
                                                <input type="hidden" id="tag_list" name="tag" />
                                                <ul class="list_tag">
                                                    <li class="add">
                                                        <span class="tagwrap">
                                                            <input id="new_tag" class="text w_8 ac_input valid" type="text" autocomplete="off">
                                                        </span>
                                                        <a id="add_tag" class="btn_2 ml_1 btn">添 加</a>
                                                    </li>
                                                </ul>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Relation) {
                                                <span>实现中</span>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Comment) {
                                                <span>无</span>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Quiz) {
                                                <span>创建内容后方可管理</span>
                                            } else {
                                                <textarea name="field.@item.FieldName" id="@item.FieldName" ></textarea>
                                                <script type="text/javascript">
                                                    var edit = UE.getEditor('@item.FieldName');
                                                </script>
                                                <div class="exp ml_1">@item.Hint</div>@*
                                                if (((Dictionary<long, string>)ViewBag.KeywordDict).ContainsKey(item.Id))
                                                {
                                                <br />
                                                <input type="button" value="点击提取关键字" onclick=' getContentTxt("@item.FieldName    ", @item.Id) ' />
                                                <br />
                                                <span style="float: left;">关键字：</span>
                                                <input type="text" name="keyword.@item.Id" id="keyword_@item.FieldName" value="@ViewBag.KeywordDict[item.Id]"  />
                                                }*@
                                            }
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
            }
            @if (isSeo) {
                <div class="table_form form_main ">
                    <div class="scrolltab-item-t">
                        <span class="btn"></span>SEO设置
                    </div>
                    <div class="pl_2">
                        <table>
                            <tbody>
                                <tr>
                                    <th width="80">页面标题：</th>
                                    <td>
                                        <input type="text" class="text w_37" name="seo.Title" />
                                    </td>
                                </tr>
                                <tr>
                                    <th width="60">页面关键字：</th>
                                    <td>
                                        <input type="text" class="text w_37" name="seo.Keyword" />
                                    </td>
                                </tr>
                                <tr>
                                    <th width="60">页面描述：</th>
                                    <td>
                                        <textarea name="seo.Description" class="w_58 h_10"></textarea>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            }
        </div>
        <div class="submitbox p_2 extra_normal">
            <input type="submit" class="btn_1 j_submit" value="提    交" />
            <ul style="display: none" id="tag_source">
                @foreach (var tag in @ViewBag.TagList) {
                    <li>@tag.Title</li>
                }
            </ul>
        </div>
    </form>
</div>
<script>

    $(function () {
        $("#pbody > .extra").addClass("scrolltab");
        $(".scrolltab").each(function () {
            var $this = $(this);
            $this.scrollTab({
                offset: 180,
                beforeActive: function ($item) {
                    var $tabContainer = $this.find(".scrolltab-triggers");
                    if ($this.hasClass("scrolltab-2") ? ($this.scrollTop() <= 60) : ($this.scrollTop() <= 100)) {
                        $tabContainer.css({ "position": "relative", top: 0, width: $tabContainer.parent().width() });
                    } else {
                        $tabContainer.css({ "position": "fixed", top: 61, width: $tabContainer.parent().width() });
                    }
                }
            });
        });
    });
    function ajaxLoadList() {
        $.ajax({
            url: "/m/menu/MenuNodeDetatil/@menu.Id",
            beforeSend: function () {
                $('.loading').show();
            },
            success: function (data) {
                $('.js_ajaxLoad').html(data);
                $('.loading').hide();
            }
        });
    }
    $('.j_submit').click(function (e) {
        var $this = $(this).parents('form');
        e.preventDefault();
        $.post("/m/node/CheckNode", $this.serialize(), function (result) {
            if (result != null) {
                if (result.Status == 3) {
                    $.confirm("检索到回收站里有重复的标题，是否继续", function () {
                        $this.submit();
                    });
                } else {
                    $.confirm("检索有重复的标题，是否继续", function () {
                        $this.submit();
                    });
                }

            } else {
                $this.submit();
            }
        });
    });
</script>
<script type="text/javascript" src="/Themes/CoralAdmin/_misc/scripts/ajaxLoad.js"></script>
